package com.neusoft.elmboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.neusoft.elmboot.po.Cart;
import com.neusoft.elmboot.service.CartService;

@RestController
@RequestMapping("/Carts")
public class CartController {

	@Autowired
	private CartService cartService;
	
	@GetMapping("/userId/{userId}")
	public List<Cart> listCart(Cart cart, @PathVariable(required = false) Integer businessId) throws Exception{
		if(businessId != null) {
			cart.setBusinessId(businessId);
		}
		return cartService.listCart(cart);
	}
		
	@PostMapping("/userId/{userId}/businessId/{businessId}/foodId/{foodId}")
	public int saveCart(Cart cart) throws Exception{
		return cartService.saveCart(cart);
	}
	
	@PutMapping("/userId/{userId}/businessId/{businessId}/foodId/{foodId}/quantity/{quantity}")
	public int updateCart(Cart cart) throws Exception{
		return cartService.updateCart(cart);
	}
	
	@DeleteMapping("/userId/{userId}/businessId/{businessId}")
	public int removeCart(Cart cart, @PathVariable(required = false) Integer foodId ) throws Exception{
		if(foodId != null) {
			cart.setFoodId(foodId);;
		}
		return cartService.removeCart(cart);
	}
}
